//
//  ZhangDieView.m
//  GuShiNews
//
//  Created by huachun on 2019/8/26.
//  Copyright © 2019 Jones. All rights reserved.
//

#import "ZhangDieView.h"
#import "LunTanModel.h"

@interface ZhangDieView ()

@end

@implementation ZhangDieView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        
        NSArray *linlist = @[@"  看涨",@"  不确定",@"  看跌"];
        [linlist enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            UILabel *linelabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 20*idx, RECRWITCH-20, 10)];
            linelabel.text = obj;
            linelabel.textColor = [UIColor whiteColor];
            linelabel.font = [UIFont systemFontOfSize:9];
            linelabel.layer.cornerRadius = 5.0;
            linelabel.layer.masksToBounds=YES;
            [self addSubview:linelabel];
            if (idx==0) {
                linelabel.backgroundColor = [JonesClass stringTOColor:@"#d81e06"];
                self.linelabel001 = linelabel;
            }else if (idx==1){
                linelabel.backgroundColor = [JonesClass stringTOColor:@"#1296db"];
                self.linelabel002 = linelabel;
            }else{
                linelabel.backgroundColor = [JonesClass stringTOColor:@"#069d17"];
                self.linelabel003 = linelabel;
            }
        }];
        
    }
    return self;
}

- (void)setModel:(LunTanModel *)Model{
    if (_Model!=Model) {
        _Model = Model;
    }
    
    int max_s = [self max_de];
    CGFloat w_danw = (RECRWITCH/2)/max_s;
    
    if ([_Model.l_ok intValue]>0) {
        self.linelabel001.text = [NSString stringWithFormat:@"  看涨(%@)",_Model.l_ok];
        self.linelabel001.frame=CGRectMake(0, 0, 40+w_danw*[_Model.l_ok intValue], 10);
    }else{
        self.linelabel001.frame=CGRectMake(0, 0, 40, 10);
        self.linelabel001.text = [NSString stringWithFormat:@"  看涨"];
    }
    if ([_Model.l_abc intValue]>0) {
        self.linelabel002.text = [NSString stringWithFormat:@"  不确定(%@)",_Model.l_abc];
        self.linelabel002.frame=CGRectMake(0, 20, 40+w_danw*[_Model.l_abc intValue], 10);
    }else{
        self.linelabel002.frame=CGRectMake(0, 20, 40, 10);
        self.linelabel002.text = [NSString stringWithFormat:@"  不确定"];
    }
    if ([_Model.l_no intValue]>0) {
        self.linelabel003.text = [NSString stringWithFormat:@"  看跌(%@)",_Model.l_no];
        self.linelabel003.frame=CGRectMake(0, 40, 40+w_danw*[_Model.l_no intValue], 10);
    }else{
        self.linelabel003.frame=CGRectMake(0, 40, 40, 10);
        self.linelabel003.text = [NSString stringWithFormat:@"  看跌"];
    }
}

- (int)max_de{     //用的是button按键 点击这个按键就能得到最大值
    int a=[_Model.l_ok intValue];//将第一个文本框中输入的值赋值给a
    int   b=[_Model.l_abc intValue];//将第二个文本框中输入的值赋值给b
    int c=[_Model.l_no intValue];//将第三个文本框中输入的值赋值给c
    if(a>b){       //这里就是用的c语言中的三个数的比较法
        if(a>c){
            return a;
        }
        else
             return c;
    }else
        if(b>c){
             return b;
            
        }else
             return c;
}

@end
